package sz.szsmk.citizencard.db.operate;

import org.greenrobot.greendao.query.QueryBuilder;

import java.util.List;

import sz.szsmk.citizencard.DaggerApplication;
import sz.szsmk.citizencard.db.DaoSession;
import sz.szsmk.citizencard.db.Note;

/**
 * Created by wangzhongfu on 2017/6/6.
 */

public class LocalDbOpt {

    private DaoSession mDaoSession;

    private static LocalDbOpt instance = null;

    public static LocalDbOpt getInstance() {
        if (null == instance) {
            instance = new LocalDbOpt(DaggerApplication.getmDaoSession());
        }
        return instance;
    }

    /**
     * 构造方法
     */
    public LocalDbOpt(DaoSession mDaoSession) {
        super();
        this.mDaoSession = mDaoSession;
    }

    public void insertNote(final Note note) {
        mDaoSession.runInTx(new Runnable() {
            @Override
            public void run() {
                mDaoSession.insert(note);
            }
        });
    }

    public List<Note> getNoteList() {
        QueryBuilder qb = mDaoSession.getNoteDao().queryBuilder();
        List<Note> noteList = qb.list();
        return noteList;
    }
}
